Imports System.Data.SqlClient


Public Class Operacion1



    Public Function LeerRegistro() As Registro

        StringComando1 = "SELECT TOP 1 * FROM CUENTA1"
        Dim Conecta1 As New SqlConnection(StringConecta1)
        Conecta1.Open()
        Comando1 = New SqlCommand(StringComando1, Conecta1)
        Adapter1 = New SqlDataAdapter(StringComando1, Conecta1)
        Ds1 = New DataSet
        Adapter1.Fill(Ds1, "REGISTRO1")

        Dim Cuenta As Integer = Ds1.Tables(0).Rows(0).Item(0)
        Dim Importe As Decimal = Ds1.Tables(0).Rows(0).Item(1)

        Dim Registro As New Registro

        Registro.Cuenta = Cuenta
        Registro.Importe = Importe

        Conecta1.Close()
        Conecta1.Dispose()

        Return Registro

    End Function

    Public Function BorrarRegistro(ByVal registro As Registro) As Boolean

        Try

            Dim Cuenta As Integer = registro.Cuenta
            Dim Importe As String = registro.Importe.ToString.Replace(",", ".")

            StringComando1 = "DELETE FROM CUENTA1 WHERE "
            StringComando1 += "CUENTA=" & Cuenta & " AND "
            StringComando1 += "IMPORTE=" & Importe

            Dim Conecta1 As New SqlConnection(StringConecta1)
            Conecta1.Open()
            Comando1 = New SqlCommand(StringComando1, Conecta1)
            Comando1.ExecuteNonQuery()

            Conecta1.Close()
            Conecta1.Dispose()


            Return True

        Catch ex As Exception

            MsgBox(ex.Message)
            Return False

        End Try

    End Function


    Public Function CuentaRegistros1() As Integer

        StringComando1 = "SELECT COUNT (*) FROM cuenta1"
        Dim Conecta1 As New SqlConnection(StringConecta1)
        Conecta1.Open()
        Comando1 = New SqlCommand(StringComando1, Conecta1)
        Adapter1 = New SqlDataAdapter(StringComando1, Conecta1)
        Ds1 = New DataSet
        Adapter1.Fill(Ds1, "REGISTRO1")
        Dim RegistrosCuenta1 As Integer = Ds1.Tables(0).Rows(0).Item(0)

        Conecta1.Close()
        Conecta1.Dispose()

        Return RegistrosCuenta1


    End Function

End Class
